package com.nowcoder.community.utils;/**
 * 功能描述
 *
 * @author 21775
 * @date 2022/09/14  20:43
 */

import lombok.extern.slf4j.Slf4j;
import org.springframework.mail.javamail.JavaMailSender;

import javax.annotation.Resource;
import javax.mail.internet.MimeMessage;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.stereotype.Component;
import org.thymeleaf.TemplateEngine;


/**
 *@ClassName MailClient
 *@Description TODO 邮箱类
 *@Author 21775
 *@Date 2022/9/14 20:43
 *@Version 1.0
 */
@Slf4j
@Component
public class MailClient {
    @Resource
    private JavaMailSender mailSender;

    @Value("${spring.mail.username}")
    private String from;

    public void sendMail(String to,String subject,String content){
        try {
//            log.info(content);
            MimeMessage message=mailSender.createMimeMessage();
            MimeMessageHelper helper=new MimeMessageHelper(message);
            helper.setFrom(from);
            helper.setTo(to);
            helper.setSubject(subject);
            helper.setText(content,true);
            mailSender.send(helper.getMimeMessage());
        }catch (Exception e){
            log.error(e.getMessage());
        }


    }
}
